/*********************************************************************
Replication Materials for "Explanation Giving Promotes Democratic Satisfaction Regardless of Respondent Partisanship"

Syntax produces the models discussed in Online Appendix F Tables OF1) 
The syntax also produces the output that will be plotted in Figure OF1 (via an R syntax file). 
***********************************************************************/

/*******************
Working Directory and Data
Update working directory to where you have the data
********************/

cd "C:\Users\jar68\OneDrive\Ongoing Work\Explanations and Dem Support\P. Behavior\Revision\R2\RR3\FINAL\Dataverse\"
use "ess_final.dta"

**Dropping non-democracies; Bulgaria had caretaker gov't
drop if country == "Albania" | country == "Russia" | country == "Kosovo" | country == "Ukraine" | country == "Bulgaria"

/*********************************
Weights
*********************************/

gen anweight = pspwght*pweight
label var anweight "Analysis Weight"


/*********************************
Models
*********************************/

eststo clear
local conts " std_courts std_elections std_econ std_life std_socialtrust i.ideol_ext1 std_ladder c.age i.gender i.minority i.citizen i.east_europe c.enep_comb c.unemp_ch"
foreach var in gov_satis dem_satis {
	eststo: mixed `var' c.std_explains##c.std_educ c.reason_std##c.std_educ c.std_interest i.co_partisan `conts' [pweight=anweight] || country: 
			*std_explains by education			
			margins, dydx(std_explains) at(std_educ=(-2(1)2)) saving(`var'_explain_educ, replace)
			*reason_std by education
			margins, dydx(reason_std) at(std_educ=(-2(1)2)) saving(`var'_reason_educ, replace)
	eststo: mixed `var' c.std_explains##c.std_interest c.reason_std##c.std_interest c.std_educ i.co_partisan  `conts' [pweight=anweight] || country: 
			*std_explains by education			
			margins, dydx(std_explains) at(std_interest =(-2(1)2)) saving(`var'_explain_interest, replace)
			*reason_std by education
			margins, dydx(reason_std) at(std_interest =(-2(1)2)) saving(`var'_reason_interest, replace)
}


***Full Table
esttab using table_of1.rtf, label onecell replace se b(3) aic bic nobaselevels ///
		transform(ln*: exp(2*@) 2*exp(2*@)) ///
		eqlabels("" "var(Constant)" "var(Residual)", none) ///
		mtitles("Gov" "Gov" "Dem" "Dem") ///
		title("{\b Table OF1}: Explanation Giving and Political Support: Education & Interest Interactions") ///
		addnotes("DV ranges from 0-10. All continuous variables are country-standardized save for age in years. Analyses use survey weights.")

		